package fishBids.group3;



import jade.content.lang.Codec;
import jade.content.lang.sl.SLCodec;
import jade.content.onto.Ontology;
import jade.core.Agent;
import jade.util.leap.HashMap;
import jade.util.leap.Map;
import es.upm.agents.ontology.Fish_BidsOntology;
import fishBids.group3.behaviour.market.MarketBuyProductBehaviour;
import fishBids.group3.behaviour.market.MarketGetPriceBehaviour;
import fishBids.group3.behaviour.market.MarketSellProductBehaviour;
import fishBids.group3.behaviour.market.MarketSellProductNotPriceVariationBehaviour;
import fishBids.group3.common.Constants;
import fishBids.group3.utils.Utils;






/**
 * This agent has the following functionality: 
 * <ul>
 * <li> It registers itself in the DF as MARKET
 * <li> Waits for getPrice querys of its market service
 * <li> If any getPrice query arrives, it answers with price of the product
 * </ul>
 * @author Gabriel & Mai, UPM
 * @version $Date: 2009/04/01 13:45:18 $ $Revision: 1.1 $
 **/





public class AgMarket extends Agent {



	/**
	 * 
	 */
	private static final long serialVersionUID = 8072333016124363057L;


	private Codec codec = new SLCodec(); 
	private Ontology ontology = Fish_BidsOntology.getInstance(); 


	protected void setup()

	{

		//System.out.println("Market3: enters into the system");
		this.getContentManager().registerLanguage(codec); 
		this.getContentManager().registerOntology(ontology);
		
		Utils.registerInDF(this.getName(), Constants.MARKET, this);
		doWait(10000);



//		BEHAVIOURS ****************************************************************

	// Adds a behavior to answer the getPrice
	// Waits for a request and, when it arrives, answers with the price of the product.
	addBehaviour(new MarketGetPriceBehaviour(this, codec, ontology));
	addBehaviour(new MarketSellProductBehaviour(this, codec, ontology));
	addBehaviour(new MarketSellProductNotPriceVariationBehaviour(this, codec, ontology));
	addBehaviour(new MarketBuyProductBehaviour(this, codec, ontology));

    }

	Map itemsPrices = readPrices();


	private Map readPrices() {
	
		//System.out.println("Runing get Prices");
		itemsPrices = new HashMap();
		itemsPrices.put(Constants.CALAMARI_TYPE.getType(), new Float (Utils.getProperty(Constants.INITIAL_CALAMARI)));
		itemsPrices.put(Constants.PRAWN_TYPE.getType(), new Float (Utils.getProperty(Constants.INITIAL_PRAWN)));
		itemsPrices.put(Constants.SALMON_TYPE.getType(), new Float (Utils.getProperty(Constants.INITIAL_SALMON)));
		itemsPrices.put(Constants.TUNA_TYPE.getType(), new Float (Utils.getProperty(Constants.INITIAL_TUNA)));
		
		return itemsPrices;
	}


	public Map getItemsPrices() {
		return itemsPrices;
	}


}

